package com.mycat.codegenerator.entity;

import java.sql.Types;

/**
 * Created by Administrator on 2016/10/22.
 */
public class Column {
    // 列名
    private String name;
    // 是否自增
    private boolean isAutoincrement;
    // 数据类型
    private String dataType;
    // 备注
    private String remarks;

    public Column() {
    }

    public Column(String name, boolean isAutoincrement, String dataType, String remarks) {
        this.name = name;
        this.isAutoincrement = isAutoincrement;
        this.dataType = dataType;
        this.remarks = remarks;
    }

    @Override
    public String toString() {
        return "Column{" +
                "name='" + name + '\'' +
                ", isAutoincrement=" + isAutoincrement +
                ", dataType='" + dataType + '\'' +
                ", remarks='" + remarks + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean getIsAutoincrement() {
        return isAutoincrement;
    }

    public void setIsAutoincrement(String isAutoincrement) {
        if ("YES".equalsIgnoreCase(isAutoincrement)) {
            this.isAutoincrement = true;
        } else {
            this.isAutoincrement = false;
        }
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        switch (Integer.parseInt(dataType)) {
            case Types.BIGINT:
                this.dataType = "Long";
                break;
            case Types.SMALLINT:
            case Types.TINYINT:
            case Types.INTEGER:
                this.dataType = "Integer";
                break;
            case Types.BOOLEAN:
            case Types.BIT:
                this.dataType = "Boolean";
                break;
            case Types.CHAR:
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
            case Types.LONGNVARCHAR:
                this.dataType = "String";
                break;
            case Types.DATE:
            case Types.TIMESTAMP:
            case Types.TIME:
                this.dataType = "Date";
                break;
            case Types.DOUBLE:
            case Types.DECIMAL:
                this.dataType = "Double";
                break;
            case Types.FLOAT:
                this.dataType = "Float";
                break;
        }
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
}
